{extend name="base" /}
{block name="content"}
<script src="__STATIC__/public/My97DatePicker/WdatePicker.js"></script>
<div class="g-main">
    <div class="m-main-title">
        <div class="m-container-fluid">
            <a href="{:url('index/welcome')}">
                <i class="icon icon-home"></i>首页</a>
            <span class="icon-angle-right"></span>
            <span>商城</span>
            <span class="icon-angle-right"></span>
            <span>直播间管理</span>
            <span class="icon-angle-right"></span>
            <span>直播间商品</span>
            <a class="u-flush">
                <i class="icon-repeat"></i>
            </a>
        </div>
    </div>
    <div class="m-main-content">
        <div class="m-container">

            <table class="m-table">
                <tbody>
                <tr>
                    <td width="15%"><label for="title">直播间名称<em>*</em></label></td>
                    <td>{$info.title}</td>
                </tr>

                <tr>
                    <td colspan="2">
                        <div class="m-options cf">
                        <div class="m-opts fl"><a href="javascript:;" class="u-btn"><i class="icon-plus"></i>选择商品</a></div>
                        </div>
                    </td>
                </tr>


            </table>
            <form class="layui-form" id="j_form" style="padding-top: 20px;">
                <table class="m-table ">
                    <tbody>
                        <tr>
                            <th width="5%">ID</th>
                            <th width="10%">商品名称</th>
                            <th width="10%">销售价格</th>
                            <th width="10%">直播间价格</th>
                            <th width="10%">库存</th>
                            <th width="10%">时间</th>
                            <th width="10%">规格</th>
                            <th width="10%">操作</th>
                        </tr>
                        {foreach name="data" item="v"}
                        <tr>
                            <td>{$v.id}</td>
                            <td>{$v.goods_info.goods_name}</td>
                            <td>{$v.goods_info.sale_price}</td>
                            <td><input type="text" class="u-ipt u-ipt-small act_price" data-id="{$v.id}" name="act_price"  placeholder="请输入价格" value="{$v.sale_price|default=0}" />元</td>
                            <td>{$v.goods_info.goods_stock}</td>
                            <td>{$v.create_time}</td>
							<td class="m-opt">
								<a href="javascript:;" class="s_btn" data-live-id="{$v.live_id}" data-goods-id="{$v.goods_id}"  title="">设置规格价格</a>
							</td>
							<td class="m-opt">
                                <a href="javascript:;" title="删除" class="a-u-del" data-id="{$v.id}"><i class="icon-trash"></i></a>
							</td>

                        </tr>
                        {/foreach}
                    </tbody>
                </table>

            </form>
        </div>
    </div>
</div>
{/block}{block name="extrajs"}

<script>
    $(function(){
        layui.use('layer', function(){
            $('.u-btn').on('click', function () {
                layer.open({
                    type: 2,
                    title: '直播商品',
                    shadeClose: false,
                    shade: 0,
                    area: ['96%', '90%'],
                    content: '/manage/live/getgoods?id='+"{$info.id}" //iframe的url
                });
            });

            $('.act_price').on('change',function () {
                var id =$(this).attr('data-id');
                var sale_price=$(this).val();

                $.post('/manage/live/setPrice',{id:id,sale_price:sale_price},function (res) {
                    if(res.code===1){
                        layer.msg(res.msg)
                    }else{
                        layer.msg(res.msg)
                    }
                })
            })

            $('.group_num').on('change',function () {
                var id =$(this).attr('data-id');
                var group_num=$(this).val();

                $.post('/manage/live/setGroup',{id:id,group_num:group_num},function (res) {
                    if(res.code===1){
                        layer.msg(res.msg)
                    }else{
                        layer.msg(res.msg)
                    }
                })
            })
            $('.s_btn').on('click', function () {
                var goods_id=$(this).attr('data-goods-id');//商品id
                var live_id =$(this).attr('data-act-id');//活动id

                layer.open({
                    type: 2,
                    title: '规格价格',
                    shadeClose: false,
                    shade: 0,
                    area: ['80%', '70%'],
                    content: '/manage/live/addsku?goods_id='+goods_id+"&live_id="+live_id//iframe的url
                });
            });
        })


        //删除
        /**
         * 删除
         */
        $('.a-u-del').on('click', function(){
            var id = $(this).attr('data-id');
            dialog.confirm('您确定删除此信息吗？', function(){
                $.get('/manage/live/delActGoods',{id:id},function (res) {
                    if(res.code===1){
                        layer.msg(res.msg);
                        setTimeout(function () {
                            window.location.reload();
                        },500);
                    }else{
                        layer.msg(res.msg)
                    }
                })
            });
            return false;
        });
    })
</script>
{/block}
